//
//  OASendDocViewController.m
//  LongOA
//
//  Created by XuJiuming on 15/10/7.
//  Copyright (c) 2015年 梁文朗. All rights reserved.
//

#import "OASendDocViewController.h"
#import "MessagePhotoView.h"
#import "MessagePhotoMenuItem.h"
#import "OASelectFileViewController.h"
#import "OADemoTempViewController.h"
#import "OAFlowListViewController.h"
#import "OADocSaveRequest.h"
#import "OADocSaveResponse.h"
#import "GetOADemoDetailRequest.h"
#import "GetOADemoDetailResponse.h"
#import "GetOAFlow_step_fjRequest.h"
#import "GetOAFlow_step_fjResponse.h"

@interface OASendDocViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,MessagePhotoViewDelegate,MessagePhotoItemDelegate,UIScrollViewDelegate,ZYQAssetPickerControllerDelegate,UIAlertViewDelegate>
{
    UITextField* txtTitle;
    UITextField* txtContent;
    UITextField* txtValue;
    UITextField* txtRemark;
    UITextField* txtTime;
    UITextField* txtSpecial;
}
@property (nonatomic) UIImagePickerController *imagePickerController;
@property(nonatomic,strong) NSMutableArray *itemArray;
@property(nonatomic,strong) NSMutableArray *imageArray;
@property(nonatomic,strong) UIScrollView *photoScrollView;
@property (nonatomic,strong) MessagePhotoView *photoView;
@property (nonatomic,strong) NSMutableArray* imgArr;
@property (nonatomic) int flowid;
@property (nonatomic) int idemoid;
@property (nonatomic,strong) NSString* strdemoCode;
@property (nonatomic) int iflowSortType;

@property (nonatomic,strong) NSArray* arrflowsort;
@property (nonatomic,strong) NSArray* arrflowstepname;
@property (nonatomic,strong) NSArray* arrflowempstr;
@property (nonatomic,strong) NSArray* arrflowempid;
@property (nonatomic,strong) NSArray* arrflowinfo;
@property (nonatomic,strong) NSArray* arrlimithour;
@property (nonatomic,strong) NSArray* arrifnecessary;
@property (nonatomic,strong) NSArray* arrifjoin;
@property (nonatomic,strong) NSArray* arrfjname;
@property (nonatomic,strong) NSArray* arrfjdata;
@property (nonatomic,strong) NSArray* arrfjtype;
@property (nonatomic,strong) NSArray* arrifdown;
@property (nonatomic,strong) NSArray* arriflook;
@property (nonatomic,strong) NSArray* arrmodelflag;
@property (nonatomic,strong) NSArray* arrgetBack;
@property (nonatomic,strong) NSArray* arrifmain;
@end

@implementation OASendDocViewController

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex==0) {
        [self dismissViewControllerAnimated:NO completion:nil];
    } else {
        [self saveData:1 withid:0];
    }
}
- (void)leftBarClicked:(id)sender {
    if (txtTitle.text.length>0) {
        UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"是否保存到草稿箱?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    } else {
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}

- (void)rightBarClicked3:(id)sender {
    //刷新
    txtTitle.text=@"";
    txtContent.text=@"";
    txtValue.text=@"0.0";
    txtRemark.text=@"";
    txtTime.text=@"";
    txtSpecial.text=@"";
}
- (void)rightBarClicked2:(id)sender {
    //保存
    [self saveData:0 withid:0];
}
- (void)rightBarClicked1:(id)sender {
    //发送
    [self saveData:2 withid:0];
}
//0 保存 1 保存草稿  2 保存发出
- (void)saveData:(int)savetype withid:(int)docid {
    if (txtTitle.text.length==0) {
        [self showAlertWithContent:@"请输入标题"];
        return;
    }
    if (txtContent.text.length==0) {
        [self showAlertWithContent:@"请输入内容"];
        return;
    }
    if (txtValue.text.length==0) {
        [self showAlertWithContent:@"请输入权值"];
        return;
    }
    if (txtRemark.text.length==0) {
        [self showAlertWithContent:@"请输入公文备注"];
        return;
    }
    if (txtTime.text.length==0) {
        [self showAlertWithContent:@"请输入时限要求"];
        return;
    }
    if (txtSpecial.text.length==0) {
        [self showAlertWithContent:@"请输入特殊要求"];
        return;
    }
    if (_flowid==0) {
        [self showAlertWithContent:@"必须选择一个流程"];
        return;
    }
    NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
    
    OADocSaveRequest* request = [[OADocSaveRequest alloc] init];
    request.token = token;
    request.docid = docid;
    request.title=txtTitle.text;
    request.content=txtContent.text;
    request.dscrp=txtRemark.text;
    request.timedscrp=txtTime.text;
    request.specialdscrp=txtSpecial.text;
    request.savetype=savetype;
    request.relqty=[txtValue.text floatValue];
    request.flowid=_flowid;
    request.dtype=0;
    request.billcode=@"";
    
    request.reldemocode=_strdemoCode;
    request.reldemoid=_idemoid;
    request.flowSortType=_iflowSortType;
    
    request.flowsort=_arrflowsort;
    request.flowstepname=_arrflowstepname;
    request.flowempstr=_arrflowempstr;
    request.flowempid=_arrflowempid;
    request.flowinfo=_arrflowinfo;
    request.limithour=_arrlimithour;
    request.ifnecessary=_arrifnecessary;
    request.ifjoin=_arrifjoin;
    request.fjname=_arrfjname;
    request.fjdata=_arrfjdata;
    request.fjtype=_arrfjtype;
    request.ifdown=_arrifdown;
    request.iflook=_arriflook;
    request.modelflag=_arrmodelflag;
    request.getBack=_arrgetBack;
    request.ifmain=_arrifmain;
    
    
    id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
    [clinet Doexecute:request
             RspClass:[OADocSaveResponse class]
               andMsg:@"获取信息..."
              andView:self.view
globalTimelinePostsWithBlock:^(id rsp) {
    OADocSaveResponse* rslt = rsp;
    
    if (rslt.ErrMsg) {
        NSLog(@"%@",rslt.ErrMsg);
    }
    else{
        NSLog(@"id=%i",rslt.docid);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshData" object:nil];
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}];
}
- (void)flowSelect:(NSNotification*)notification {
    NSDictionary* dict=notification.object;
    //NSLog(@"%@",dict);
    _flowid=[[dict objectForKey:@"flowid"] intValue];
    [self flow_fj:_flowid];
    /*
     {
     billtypead = 94;
     dscrp = "\U6d41\U7a0b\U5907\U6ce8";
     flowempstrs = "abc>asd>\U5458\U5de53";
     flowid = 13;
     flowname = "\U6d41\U7a0b\U540d\U79f0";
     flowtype = "\U6d4b\U8bd5\U6d41\U7a0b";
     "if_rivet" = 0;
     moddate = "2014-11-04 10:05:36";
     modemp = "\U8d85\U7ea7\U7528\U6237";
     opdate = "2014-03-11 09:11:33";
     opemp = "\U8d85\U7ea7\U7528\U6237";
     relation = "\U603b\U6570\U91cf  >  0.1";
     sortnum = 001;
     }
     */
}
- (void)flow_fj:(int)flowid {
    NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
    
    GetOAFlow_step_fjRequest* request = [[GetOAFlow_step_fjRequest alloc] init];
    request.token = token;
    request.flowid=flowid;
    id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
    [clinet Doexecute:request
             RspClass:[GetOAFlow_step_fjResponse class]
               andMsg:@"获取信息..."
              andView:self.view
globalTimelinePostsWithBlock:^(id rsp) {
    GetOAFlow_step_fjResponse* rslt = rsp;
    
    if (rslt.ErrMsg) {
        NSLog(@"%@",rslt.ErrMsg);
    }
    else{
//        NSLog(@"steps=%@",rslt.steps);
//        NSLog(@"fjs=%@",rslt.fjs);
        if ([rslt.steps count]>0) {
            NSMutableArray* aflowsort=[[NSMutableArray alloc] init];
            NSMutableArray* aflowstepname=[[NSMutableArray alloc] init];
            NSMutableArray* aflowempstr=[[NSMutableArray alloc] init];
            //NSMutableArray* aflowempid=[[NSMutableArray alloc] init];
            NSMutableArray* aflowinfo=[[NSMutableArray alloc] init];
            NSMutableArray* aflowlimithour=[[NSMutableArray alloc] init];
            NSMutableArray* aifnecessary=[[NSMutableArray alloc] init];
            NSMutableArray* aifjoin=[[NSMutableArray alloc] init];
            //NSMutableArray*
            for (int i=0; i<[rslt.steps count]; i++) {
                NSDictionary* dict=[rslt.steps objectAtIndex:i];
                [aflowsort addObject:[dict objectForKey:@"flowsort"]];
                [aflowstepname addObject:[dict objectForKey:@"flowstepname"]];
                [aflowempstr addObject:[dict objectForKey:@"flowempstr"]];
                //[aflowempid addObject:[dict objectForKey:@"flowempid"]];
                [aflowinfo addObject:[dict objectForKey:@"flowinfo"]];
                [aflowlimithour addObject:[dict objectForKey:@"limithour"]];
                [aifnecessary addObject:[dict objectForKey:@"ifnecessary"]];
                [aifjoin addObject:[dict objectForKey:@"ifjoin"]];
            }
            
            _arrflowsort=aflowsort;
            _arrflowstepname=aflowstepname;
            _arrflowempstr=aflowempstr;
            _arrflowempid=@[]; //aflowempid;
            _arrflowinfo=aflowinfo;
            _arrlimithour=aflowlimithour;
            _arrifnecessary=aifnecessary;
            _arrifjoin=aifjoin;
        } else {
            _arrflowsort=@[];
            _arrflowstepname=@[];
            _arrflowempstr=@[];
            _arrflowempid=@[];
            _arrflowinfo=@[];
            _arrlimithour=@[];
            _arrifnecessary=@[];
            _arrifjoin=@[];
        }
        
        
        if (rslt.fjs.count>0) {
            NSMutableArray* afilename=[[NSMutableArray alloc] init];
            NSMutableArray* aifmain=[[NSMutableArray alloc] init];
            NSMutableArray* amodelflag=[[NSMutableArray alloc] init];
            NSMutableArray* agetback=[[NSMutableArray alloc] init];
            
            //NSMutableArray*
            for (int i=0; i<[rslt.fjs count]; i++) {
                NSDictionary* dict=[rslt.fjs objectAtIndex:i];
                [afilename addObject:[dict objectForKey:@"fileName"]];
                [aifmain addObject:[dict objectForKey:@"ifmain"]];
                [amodelflag addObject:[dict objectForKey:@"modelflag"]];
                [agetback addObject:[dict objectForKey:@"fileID"]];
            }
            _arrfjname=afilename;
            _arrfjdata=@[];
            _arrfjtype=@[];
            _arrifdown=@[];
            _arriflook=@[];
            _arrmodelflag=amodelflag;
            _arrgetBack=agetback;
            _arrifmain=aifmain;
        } else {
            _arrfjname=@[];
            _arrfjdata=@[];
            _arrfjtype=@[];
            _arrifdown=@[];
            _arriflook=@[];
            _arrmodelflag=@[];
            _arrgetBack=@[];
            _arrifmain=@[];
        }
    }
}];
}
- (void)demoSelect:(NSNotification*)notification {
    UIButton* btn=(UIButton*)[self.view viewWithTag:6012];
    btn.enabled=false;
    [btn setBackgroundColor:RGBColor(192, 192, 192, 1)];
    
    NSDictionary* dict=notification.object;
    //NSLog(@"%@",dict);
    
    _flowid=[[dict objectForKey:@"flowid"] intValue];
    _idemoid=[[dict objectForKey:@"demoid"] intValue];
    _strdemoCode=[NSString stringWithFormat:@"%@",[dict objectForKey:@"democode"]];
    _iflowSortType=[[dict objectForKey:@"if_rivet"] intValue];
    [self getDemoDetail:[[dict objectForKey:@"demoid"] intValue]];
//    txtTitle.text=[dict objectForKey:@"doctitle"];
//    txtContent.text=[dict objectForKey:@"doccontent"];
//    txtValue.text=@"0.0";
    
    /*
     {
     democode = 003;
     demoid = 12;
     doccontent = "\U8bf7\U5047";
     doctitle = "\U8bf7\U5047";
     flowid = 14;
     flowname = "\U8bf7\U5047";
     "if_rivet" = 0;
     moddate = "";
     modemp = "";
     opdate = "2015-10-20 10:29:15";
     opemp = "\U8d85\U7ea7\U7528\U6237";
     typeid = 11;
     typename = "\U884c\U653f                                              ";
     }
     */
}
- (void)getDemoDetail:(int)demoid {
    NSString* token=[[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    int setid=[[[NSUserDefaults standardUserDefaults] objectForKey:@"setid"] intValue];
    
    GetOADemoDetailRequest* request = [[GetOADemoDetailRequest alloc] init];
    request.token = token;
    request.demoid=demoid;
    id<ILJClient> clinet = [[OAIpdataBase shareInstance] getPool:setid];
    [clinet Doexecute:request
             RspClass:[GetOADemoDetailResponse class]
               andMsg:@"获取信息..."
              andView:self.view
globalTimelinePostsWithBlock:^(id rsp) {
    GetOADemoDetailResponse* rslt = rsp;
    
    if (rslt.ErrMsg) {
        NSLog(@"%@",rslt.ErrMsg);
    }
    else{
        txtTitle.text=rslt.doctitle;
        txtContent.text=rslt.doccontent;
        txtValue.text=[NSString stringWithFormat:@"%.1f",rslt.relqty];
        txtRemark.text=rslt.dscrp;
        txtTime.text=rslt.timedscrp;
        txtSpecial.text=rslt.specialdscrp;

        
        if ([rslt.steps count]>0) {
            NSMutableArray* aflowsort=[[NSMutableArray alloc] init];
            NSMutableArray* aflowstepname=[[NSMutableArray alloc] init];
            NSMutableArray* aflowempstr=[[NSMutableArray alloc] init];
            NSMutableArray* aflowempid=[[NSMutableArray alloc] init];
            NSMutableArray* aflowinfo=[[NSMutableArray alloc] init];
            NSMutableArray* aflowlimithour=[[NSMutableArray alloc] init];
            NSMutableArray* aifnecessary=[[NSMutableArray alloc] init];
            NSMutableArray* aifjoin=[[NSMutableArray alloc] init];
            //NSMutableArray*
            for (int i=0; i<[rslt.steps count]; i++) {
                NSDictionary* dict=[rslt.steps objectAtIndex:i];
                [aflowsort addObject:[dict objectForKey:@"flowsort"]];
                [aflowstepname addObject:[dict objectForKey:@"flowstepname"]];
                [aflowempstr addObject:[dict objectForKey:@"flowempstr"]];
                [aflowempid addObject:[dict objectForKey:@"flowempid"]];
                [aflowinfo addObject:[dict objectForKey:@"flowinfo"]];
                [aflowlimithour addObject:[dict objectForKey:@"limithour"]];
                [aifnecessary addObject:[dict objectForKey:@"ifnecessary"]];
                [aifjoin addObject:[dict objectForKey:@"ifjoin"]];
            }
            
            _arrflowsort=aflowsort;
            _arrflowstepname=aflowstepname;
            _arrflowempstr=aflowempstr;
            _arrflowempid=aflowempid;
            _arrflowinfo=aflowinfo;
            _arrlimithour=aflowlimithour;
            _arrifnecessary=aifnecessary;
            _arrifjoin=aifjoin;
        } else {
            _arrflowsort=@[];
            _arrflowstepname=@[];
            _arrflowempstr=@[];
            _arrflowempid=@[];
            _arrflowinfo=@[];
            _arrlimithour=@[];
            _arrifnecessary=@[];
            _arrifjoin=@[];
        }
        
        
        if (rslt.annexes.count>0) {
            NSMutableArray* afilename=[[NSMutableArray alloc] init];
            NSMutableArray* aifmain=[[NSMutableArray alloc] init];
            NSMutableArray* amodelflag=[[NSMutableArray alloc] init];
            NSMutableArray* agetback=[[NSMutableArray alloc] init];

            //NSMutableArray*
            for (int i=0; i<[rslt.annexes count]; i++) {
                NSDictionary* dict=[rslt.annexes objectAtIndex:i];
                [afilename addObject:[dict objectForKey:@"fileName"]];
                [aifmain addObject:[dict objectForKey:@"ifmain"]];
                [amodelflag addObject:[dict objectForKey:@"modelflag"]];
                [agetback addObject:[dict objectForKey:@"fileID"]];
            }
            _arrfjname=afilename;
            _arrfjdata=@[];
            _arrfjtype=@[];
            _arrifdown=@[];
            _arriflook=@[];
            _arrmodelflag=amodelflag;
            _arrgetBack=agetback;
            _arrifmain=aifmain;
        } else {
            _arrfjname=@[];
            _arrfjdata=@[];
            _arrfjtype=@[];
            _arrifdown=@[];
            _arriflook=@[];
            _arrmodelflag=@[];
            _arrgetBack=@[];
            _arrifmain=@[];
        }
//        NSLog(@"steps=%@",rslt.steps);
//        NSLog(@"annexes=%@",rslt.annexes);
    }
}];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _flowid=0;
    _imageArray=[[NSMutableArray alloc] init];
    [self createNavWithTitle:@"发起公文" createMenuItem:^UIView *(int nIndex)
     {
         float btnwidth=40.0f;
         float btnheight=40.0f;
         if (nIndex ==0)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(10.0f, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(leftBarClicked:) forControlEvents:UIControlEventTouchUpInside];
             btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
             return btn;
         }
         if (nIndex ==2)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(self.navView.width - btnwidth, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"ic_send"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(rightBarClicked1:) forControlEvents:UIControlEventTouchUpInside];
             
             return btn;
         }
         if (nIndex ==3)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(self.navView.width - btnwidth*2, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"ic_save"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(rightBarClicked2:) forControlEvents:UIControlEventTouchUpInside];
             
             return btn;
         }
         if (nIndex ==4)
         {
             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
             [btn setFrame:CGRectMake(self.navView.width - btnwidth*3, 20.0f+(self.navView.height-20 - 40)/2, btnwidth, btnheight)];
             [btn setImage:[UIImage imageNamed:@"ic_refresh"] forState:UIControlStateNormal];
             [btn addTarget:self action:@selector(rightBarClicked3:) forControlEvents:UIControlEventTouchUpInside];
             
             return btn;
         }
         return nil;
     }];
    UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(10.0, 64.0+10.0, (SCREEN_WIDTH-30.0)/2, 33.0)];
    [btn1 setTitle:@"选择公文模板" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn1.titleLabel.font=[UIFont systemFontOfSize:14.0];
    [btn1 setBackgroundColor:RGBColor(40, 119, 193, 1)];
    btn1.layer.cornerRadius=3.0;
    btn1.tag=6011;
    [btn1 addTarget:self action:@selector(demoBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(10.0+btn1.right, 64.0+10.0, (SCREEN_WIDTH-30.0)/2, 33.0)];
    [btn2 setTitle:@"选择审批流程" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn2.titleLabel.font=[UIFont systemFontOfSize:14.0];
    [btn2 setBackgroundColor:RGBColor(40, 119, 193, 1)];
    btn2.layer.cornerRadius=3.0;
    btn2.tag=6012;
    [btn2 addTarget:self action:@selector(flowBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    //中间view
    UIView* viewMiddle=[[UIView alloc] initWithFrame:CGRectMake(10.0, btn1.bottom+10.0, SCREEN_WIDTH-20.0, 150.0)];
//    viewMiddle.layer.shadowOffset = CGSizeMake(-5, 3);
//    viewMiddle.layer.shadowOpacity = 0.4;
//    viewMiddle.layer.shadowColor = [UIColor blackColor].CGColor;
    //viewMiddle.backgroundColor=[UIColor groupTableViewBackgroundColor];
    viewMiddle.layer.cornerRadius=5.0f;
    viewMiddle.layer.borderColor=[UIColor groupTableViewBackgroundColor].CGColor;
    viewMiddle.layer.borderWidth=0.5f;
    [self.view addSubview:viewMiddle];
    
    float fwidth=80.0;
    float fheight=25.0;
//    float ftxtspace=5.0;
//    float ftxtWidth=180.0;
    
    txtTitle=[self createTextField:CGRectMake(5.0, 0.0, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    txtTitle.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtTitle forWidth:-85.0];
    float bottom=[self createLabel:@"标题(必填)" withRect:CGRectMake(0.0, 0.0, fwidth, fheight) withView:viewMiddle];
    
    txtContent=[self createTextField:CGRectMake(5.0, bottom, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    //txtContent.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtContent forWidth:-85.0];
    bottom=[self createLabel:@"内容" withRect:CGRectMake(0.0, bottom, fwidth, fheight) withView:viewMiddle];
    
    txtValue=[self createTextField:CGRectMake(5.0, bottom, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    txtValue.keyboardType=UIKeyboardTypeDecimalPad;
    txtValue.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtValue forWidth:-85.0];
    bottom=[self createLabel:@"权值" withRect:CGRectMake(0.0, bottom, fwidth, fheight) withView:viewMiddle];
    
    txtRemark=[self createTextField:CGRectMake(5.0, bottom, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    ///txtRemark.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtRemark forWidth:-85.0];
    bottom=[self createLabel:@"公文备注" withRect:CGRectMake(0.0, bottom, fwidth, fheight) withView:viewMiddle];
    
    txtTime=[self createTextField:CGRectMake(5.0, bottom, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    txtTime.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtTime forWidth:-85.0];
    bottom=[self createLabel:@"时限要求" withRect:CGRectMake(0.0, bottom, fwidth, fheight) withView:viewMiddle];
    
    txtSpecial=[self createTextField:CGRectMake(5.0, bottom, viewMiddle.width-10.0, fheight) withView:viewMiddle];
    //txtSpecial.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self setTextFieldLeftPadding:txtSpecial forWidth:-85.0];
    bottom=[self createLabel:@"特殊要求" withRect:CGRectMake(0.0, bottom, fwidth, fheight) withView:viewMiddle];
    
    
    float fvHeight=26.0f;
    float fvWidth=30.0f;
    UIView *view8=[[UIView alloc] initWithFrame:CGRectMake(-1.0, SCREEN_HEIGHT-44.0, SCREEN_WIDTH+2.0, 44)];
    view8.layer.borderColor=[UIColor darkTextColor].CGColor;
    view8.layer.borderWidth=1.0f;
    view8.tag=8080;
    [self.view addSubview:view8];
    
    float fspace=(SCREEN_WIDTH-50.0*2-fvWidth*3)/2.0;
    UIButton *customButton1 = [[UIButton alloc] initWithFrame:CGRectMake(50.0, (44.0-fvHeight)/2.0, fvWidth, fvHeight)];
    [customButton1 addTarget:self action:@selector(leftBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [customButton1 setImage:[UIImage imageNamed:@"icon_attach_toolbar_camera"] forState:UIControlStateNormal];
    [customButton1 setImage:[UIImage imageNamed:@"icon_attach_toolbar_camera_pressed"] forState:UIControlStateHighlighted];
    [view8 addSubview:customButton1];
    UIButton *customButton2 = [[UIButton alloc] initWithFrame:CGRectMake(customButton1.right+fspace, (44.0-fvHeight)/2.0, fvWidth, fvHeight)];
    [customButton2 addTarget:self action:@selector(middleBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [customButton2 setImage:[UIImage imageNamed:@"icon_attach_toolbar_album"] forState:UIControlStateNormal];
    [customButton2 setImage:[UIImage imageNamed:@"icon_attach_toolbar_album_pressed"] forState:UIControlStateHighlighted];
    [view8 addSubview:customButton2];
    UIButton *customButton3 = [[UIButton alloc] initWithFrame:CGRectMake(customButton2.right+fspace, (44.0-fvHeight)/2.0, fvWidth, fvHeight)];
    [customButton3 addTarget:self action:@selector(rightBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [customButton3 setImage:[UIImage imageNamed:@"icon_attach_toolbar_file"] forState:UIControlStateNormal];
    [customButton3 setImage:[UIImage imageNamed:@"icon_attach_toolbar_file_pressed"] forState:UIControlStateHighlighted];
    [view8 addSubview:customButton3];
    
    //    self.photoView = [[MessagePhotoView alloc]initWithFrame:CGRectMake(5.0, SCREEN_HEIGHT-60.0,SCREEN_WIDTH-5.0*2, 60.0f)];
    //    [self.view addSubview:self.photoView];
    //    self.photoView.backgroundColor=[UIColor whiteColor];
    //    self.photoView.layer.borderColor=[UIColor lightGrayColor].CGColor;
    //    self.photoView.layer.borderWidth=0.6;
    //    self.photoView.layer.cornerRadius=5.0;
    //    self.photoView.delegate = self;
    //    self.photoView.hidden=YES;
    _photoScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, SCREEN_HEIGHT-80.0,SCREEN_WIDTH, 80.0f)];
    _photoScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-view8.bottom);
    _photoScrollView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    _photoScrollView.showsVerticalScrollIndicator=NO;
    _photoScrollView.showsHorizontalScrollIndicator=NO;
    _photoScrollView.hidden=YES;
    [self.view addSubview:_photoScrollView];
    _itemArray = [[NSMutableArray alloc]init];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(demoSelect:) name:@"demoSelect" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(flowSelect:) name:@"flowSelect" object:nil];
}

-(void)setTextFieldLeftPadding:(UITextField *)textField1 forWidth:(CGFloat)leftWidth
{
    CGRect frame = textField1.frame;
    frame.size.width = leftWidth;
    UIView *leftview = [[UIView alloc] initWithFrame:frame];
    textField1.leftViewMode = UITextFieldViewModeAlways;
    textField1.leftView = leftview;
}
- (float)createLabel:(NSString *)title withRect:(CGRect)rect withView:(UIView*)view {
    UILabel *lab1=[[UILabel alloc]initWithFrame:rect];
    lab1.backgroundColor=[UIColor clearColor];
    lab1.text=title;
    lab1.textAlignment=NSTextAlignmentRight;
    lab1.font=[UIFont systemFontOfSize:15.0];
    lab1.textColor=[UIColor darkGrayColor];
    [view addSubview:lab1];
    return lab1.bottom;
}
- (UITextField *)createTextField:(CGRect)rect withView:(UIView*)view{
    //UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:picName]];
    UITextField *temp = [[UITextField alloc] initWithFrame:rect];
    temp.font=[UIFont systemFontOfSize:15.0];
    temp.backgroundColor=[UIColor clearColor];
    temp.textColor=[UIColor blackColor];
    //temp.delegate=self;
    //[temp setBackgroundColor:color];
    //[Util setTextFieldLeftPadding:temp forWidth:-5.0f];
    [view addSubview:temp];
    return temp;
    
}
#pragma mark 模板选择
- (void)demoBtnPressed:(id)sender {
    OADemoTempViewController* vc=[[OADemoTempViewController alloc] init];
    //[self.navigationController pushViewController:vc animated:NO];
    [self presentViewController:vc animated:NO completion:nil];
}
- (void)flowBtnPressed:(id)sender {
    OAFlowListViewController* vc=[[OAFlowListViewController alloc] init];
    //[self.navigationController pushViewController:vc animated:NO];
    [self presentViewController:vc animated:NO completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark Bottom ToolBar
- (void)leftBtnPressed:(id)sender {
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        //
        if (!self.imagePickerController) {
            UIImagePickerController *pickerTake = [[UIImagePickerController alloc]init];
            pickerTake.delegate = self;
            //设置拍照后的图片可被编辑
            pickerTake.allowsEditing = YES;
            pickerTake.sourceType = sourceType;
            self.imagePickerController = pickerTake;
        }
        //[self presentViewController:pickerTake animated:YES completion:nil];
        
        [self presentViewController:self.imagePickerController animated:YES completion:nil];
        
    }else{
        NSLog(@"模拟器中无法打开照相机,请在真机中使用");
    }
}
- (void)middleBtnPressed:(id)sender {
    //导航栏颜色保持和当前一致
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];
    [self localPhoto];
}
- (void)rightBtnPressed:(id)sender {
    OASelectFileViewController* vc=[[OASelectFileViewController alloc] init];
    //[self.navigationController pushViewController:vc animated:NO];
    [self presentViewController:vc animated:NO completion:nil];
}
-(NSString*)GetCurrentTimeString {
    NSDateFormatter *dateformat = [[NSDateFormatter  alloc]init];
    [dateformat setDateFormat:@"yyyyMMddHHmmss"];
    return [dateformat stringFromDate:[NSDate date]];
}
#pragma mark MessagePhotoView
//实现代理方法
-(void)addPicker:(UIImagePickerController *)picker{
    [self presentViewController:picker animated:YES completion:nil];
}
-(void)selectItemArray:(NSMutableArray *)array {
    for (int i=0; i<[array count]; i++) {
        ALAsset *asset=array[i];
        CGImageRef ref = [[asset defaultRepresentation]fullScreenImage];
        //CGImageRef ref = [[asset defaultRepresentation]fullResolutionImage];
        UIImage *img = [[UIImage alloc]initWithCGImage:ref];
        
        NSString* strTime=[self GetCurrentTimeString];
        NSString* strfile=[NSString stringWithFormat:@"%@.jpg",strTime];
        NSString* strfile1=[kImagesFolder stringByAppendingPathComponent:strfile];
        [UIImageJPEGRepresentation(img, 0.5) writeToFile:strfile1 atomically:YES];
        
        [_imgArr addObject:strTime];
    }
}
- (void)takePhoto:(UIImage *)image {
    NSString* strTime=[self GetCurrentTimeString];
    NSString* strfile=[NSString stringWithFormat:@"%@.jpg",strTime];
    NSString* strfile1=[kImagesFolder stringByAppendingPathComponent:strfile];
    [UIImageJPEGRepresentation(image, 0.5) writeToFile:strfile1 atomically:YES];
    
    [_imgArr addObject:strTime];
}
-(void)addUIImagePicker:(UIImagePickerController *)picker {
    //    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
    //        self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    //    }
    [self presentViewController:picker animated:YES completion:nil];
}
-(void)deleteImage:(NSInteger)index {
    [_imgArr removeObjectAtIndex:index];
}
/*
 新加的另外的方法
 */
////////////////////////////////////////////////////////////
//打开相册，可以多选
-(void)localPhoto{
    ZYQAssetPickerController *picker = [[ZYQAssetPickerController alloc]init];
    //    picker.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:203.0f/255.0f blue:98.0f/255.0f alpha:1.0f];
    //    picker.navigationBar.tintColor = [UIColor whiteColor];
    picker.maximumNumberOfSelection = 9;
    picker.assetsFilter = [ALAssetsFilter allPhotos];
    picker.showEmptyGroups = NO;
    picker.delegate = self;
    picker.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject,NSDictionary *bindings){
        if ([[(ALAsset *)evaluatedObject valueForProperty:ALAssetPropertyType]isEqual:ALAssetTypeVideo]) {
            NSTimeInterval duration = [[(ALAsset *)evaluatedObject valueForProperty:ALAssetPropertyDuration]doubleValue];
            return duration >= 10;
        }else{
            return  YES;
        }
    }];
    
    //[self.delegate addPicker:picker];
    [self presentViewController:picker animated:YES completion:nil];
}

#pragma  mark   -ZYQAssetPickerController Delegate
/*
 得到选中的图片
 */
#pragma mark - ZYQAssetPickerController Delegate
//跳转到大图显示页面
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
    
    //[self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    //NSLog(@"self.itemArray is %lu",(unsigned long)self.photoMenuItems.count);
    
    //跳转到显示大图的页面
    //ShowBigViewController *big = [[ShowBigViewController alloc]init];
    
    //big.arrayOK = [NSMutableArray arrayWithArray:assets];
    //追加状态
    for (int i=0; i<assets.count; i++) {
        ALAsset *asset=assets[i];
        UIImage *image=[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
        
        NSString *saveUrl=[self saveImage:image withType:@"picture"];
        [self addImage:image withUrl:saveUrl withType:@"picture"];
        [_imageArray addObject:saveUrl];
        NSLog(@"ZY-_imageArray=%@",_imageArray);
        if (_photoScrollView.hidden) {
            UIView* vi1=(UIView*)[self.view viewWithTag:8080];
            CGRect frame = vi1.frame;
            frame.origin.y = SCREEN_HEIGHT-44.0-80.0;
            vi1.frame = frame;
            _photoScrollView.hidden=NO;
            //NSLog(@"assets is %lu",(unsigned long)assets.count);
        }
        
    }
    
    //    if (self.photoMenuItems.count>0) {
    //        [self.photoMenuItems addObjectsFromArray:[NSMutableArray arrayWithArray:assets]];
    //    } else
    //        self.photoMenuItems = [NSMutableArray arrayWithArray:assets];
    
    
    //NSLog(@"%lu",(unsigned long)self.photoMenuItems.count);
    //[self initlizerScrollView:self.photoMenuItems];
    //NSLog(@"arraryOk is %d",big.arrayOK.count);
    //[picker pushViewController:big animated:YES];
    [self selectItemArray:[NSMutableArray arrayWithArray:assets]];
    
}
/////////////////////////////////////////////////////////
-(NSString *)saveImage1:(UIImage *)image withType:(NSString *)type withPath:(NSString*)strPath
{
    image=[self scaleImage:image toScale:0.3];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.29);
    
    NSString *fileName = nil;//[[formatter stringFromDate:date] stringByAppendingPathExtension:@"jpg"];
    
    NSString *temp=[NSString stringWithFormat:@"%@%@",strPath,@"mi"];
    fileName=[temp stringByAppendingPathExtension:@"jpg"];
    
    
    //NSString *filePath=[sandBox stringByAppendingPathComponent:fileName];
    [imageData writeToFile:fileName atomically:YES];
    
    return fileName; //[sandBox stringByAppendingPathComponent:fileName];
}
- (UIImage *)scaleImage:(UIImage *)image1 toScale:(float)scaleSize
{
    UIGraphicsBeginImageContext(CGSizeMake(image1.size.width * scaleSize, image1.size.height * scaleSize));
    [image1 drawInRect:CGRectMake(0, 0, image1.size.width * scaleSize, image1.size.height * scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return scaledImage;
}
//将照片保存到disk上
-(NSString *)saveImage:(UIImage *)image withType:(NSString *)type
{
    //    NSData *imageData = UIImagePNGRepresentation(image);
    //    if(imageData == nil)
    //    {
    //        imageData = UIImageJPEGRepresentation(image, 1.0);
    //    }
    image=[self scaleImage:image toScale:0.3];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.29);
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMddHHmmss"];
    NSString *fileName = nil;//[[formatter stringFromDate:date] stringByAppendingPathExtension:@"jpg"];
    
    fileName = [[formatter stringFromDate:date] stringByAppendingPathExtension:@"jpg"];
    
    //    NSURL *saveURL = [NSURL URLWithString:[sandBox stringByAppendingPathComponent:fileName]];
    //    [imageData writeToURL:saveURL atomically:YES];
    NSString *filePath=[kImagesFolder stringByAppendingPathComponent:fileName];
    [imageData writeToFile:filePath atomically:YES];
    
    return filePath; //[kImagesFolder stringByAppendingPathComponent:fileName];
}
//选择某张照片之后
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //关闭相册界面
    [picker dismissViewControllerAnimated:YES completion:nil];
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    //当选择的类型是图片
    if([type isEqualToString:@"public.image"]){
        //获取照片实例
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSString *saveUrl=[self saveImage:image withType:@"picture"];
        [self addImage:image withUrl:saveUrl withType:@"picture"];
        [_imageArray addObject:saveUrl];
        NSLog(@"imageArray=%@",_imageArray);
        if (_photoScrollView.hidden) {
            UIView* vi1=(UIView*)[self.view viewWithTag:8080];
            CGRect frame = vi1.frame;
            frame.origin.y = SCREEN_HEIGHT-44.0-80.0;
            vi1.frame = frame;
            _photoScrollView.hidden=NO;
        }
        
        //保存到相册
        //        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        //        [library writeImageToSavedPhotosAlbum:[image CGImage]
        //                            orientation:(ALAssetOrientation)[image imageOrientation]
        //                            completionBlock:nil];
        
        //       NSData *datas=UIImageJPEGRepresentation(image, 0.5);
        //        UIImage *image1 = [UIImage imageWithData:datas];
        //[self reloadDataWithImage:image];
        
        //[self.delegate takePhoto:image];
        /*
         NSData *datas;
         if(UIImagePNGRepresentation(image)==nil){
         datas = UIImageJPEGRepresentation(image, 1.0);
         }else{
         datas = UIImagePNGRepresentation(image);
         }
         
         //图片保存的路径
         //这里将图片放在沙盒的documents文件夹中
         NSString *DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
         //文件管理器
         NSFileManager *fileManager = [NSFileManager defaultManager];
         //把刚才图片转换的data对象拷贝至沙盒中,并保存为image.png
         [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
         [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:datas attributes:nil];
         //得到选择后沙盒中图片的完整路径
         filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,@"/image.png"];
         
         //创建一个选择后图片的图片放在scrollview中
         
         //加载scrollview中
         */
    }
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //NSLog(@"您取消了选择图片");
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//添加图像到列表
- (void)addImage:(UIImage *)image withUrl:(NSString *)saveUrl withType:(NSString *)dataType {
    //int i=0;
    int j=0;
    float fmargin=15.0f;
    float fspace=10.0f;
    float ItemWidth = (SCREEN_WIDTH - fmargin*2 - fspace*2)/3;
    //float ItemHeight = 50.0f;
    int iColumn=0;
    int iRow=0;
    
    j=(int)[self.itemArray count]; //+1;
    //    iColumn = j%3;
    //    iRow = j/3;
    iColumn=j;
    iRow=0;
    
    MessagePhotoMenuItem *photoItem = [[MessagePhotoMenuItem alloc]initWithFrame:CGRectMake(fmargin+iColumn * (ItemWidth+fspace), iRow*(ItemWidth-10.0+7.0), ItemWidth, ItemWidth-10.0) withType:dataType];
    photoItem.delegate = self;
    photoItem.index = j;
    photoItem.contentImage = image;
    photoItem.filePath=saveUrl;
    photoItem.dataType=dataType;
    
    [self.photoScrollView addSubview:photoItem];
    [self.itemArray addObject:photoItem];
    
    //[self.photoScrollView setContentSize:CGSizeMake(SCREEN_WIDTH,(iRow+1)*ItemWidth)];
    [self.photoScrollView setContentSize:CGSizeMake((ItemWidth+10.0)*(j+1)+20.0,80)];
}
- (void)updateScrollView:(NSMutableArray *)itemList {
    [self.photoScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    float fmargin=15.0f;
    float fspace=10.0f;
    float ItemWidth = (SCREEN_WIDTH - fmargin*2 - fspace*2)/3;
    //float ItemHeight = 50.0f;
    int iColumn=0;
    int iRow=0;
    for (int j=0; j<[itemList count]; j++) {
        iColumn = j; //j%3;
        iRow = 0; //j/3;
        MessagePhotoMenuItem *photoItem = [self.itemArray objectAtIndex:j];
        photoItem.frame=CGRectMake(fmargin+iColumn * (ItemWidth+fspace), iRow*(ItemWidth-10.0+7.0), ItemWidth, ItemWidth-10.0);
        photoItem.index = j;
        photoItem.contentImage=[UIImage imageWithContentsOfFile:photoItem.filePath];
        //NSLog(@"%@---%@",photoItem.filePath,photoItem.dataType);
        [self.photoScrollView addSubview:photoItem];
        //[self.itemArray addObject:photoItem];
        [self.photoScrollView setContentSize:CGSizeMake((ItemWidth+10.0)*(j+1)+20.0,80)];
    }
}
#pragma mark - MessagePhotoItemDelegate
- (void)messagePItemView:(MessagePhotoMenuItem *)messagePItem withTouch:(NSInteger)index withImgView:(UIImageView *)imgView{
    //    if ([messagePItem.dataType isEqualToString:@"picture"]) {
    //        [self localImageShow:index withImgView:imgView];
    //    } else if ([messagePItem.dataType isEqualToString:@"video"]) {
    //        NSString *_mp4Path=messagePItem.filePath;
    //        _mp4Path= [_mp4Path stringByReplacingOccurrencesOfString:@"jpg" withString:@"mp4"];
    //        MPMoviePlayerViewController* playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[NSString stringWithFormat:@"file://localhost/private%@", _mp4Path]]];
    //        //NSLog(@"%@",[NSString stringWithFormat:@"file://localhost/private%@", _mp4Path]);
    //        playerView.moviePlayer.shouldAutoplay=NO;
    //        [self presentViewController:playerView animated:YES completion:nil];
    //        //[playerView.moviePlayer stop];
    //    } else {
    //        //music
    //        NSString *strMusic=[NSString stringWithFormat:@"%@.wav",[messagePItem.filePath stringByDeletingPathExtension]];
    //        strMusic=[strMusic stringByReplacingOccurrencesOfString:@"mi" withString:@""];
    //        [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
    //        [[AVAudioSession sharedInstance] setActive:YES error:nil];
    //        self.player = [self.player initWithContentsOfURL:[NSURL URLWithString:strMusic] error:nil];
    //        [self.player play];
    //    }
}
-(void)messagePhotoItemView:(MessagePhotoMenuItem *)messagePhotoItemView didSelectDeleteButtonAtIndex:(NSInteger)index{
    //从目录删除
    //打开拍照前，或者上传完毕删除所有文件
    //    if ([messagePhotoItemView.dataType isEqualToString:@"video"]) {
    //        NSFileManager *fm = [NSFileManager defaultManager];
    //        NSArray *fileList = [[fm contentsOfDirectoryAtPath:sandBox error:nil] pathsMatchingExtensions:[NSArray arrayWithObjects:@"mp4",nil]];
    //        for (int i=0 ; i<[fileList count]; i++) {
    //            NSError *error;
    //            NSString *filepath = [sandBox stringByAppendingPathComponent:[fileList objectAtIndex:i]];
    //            [[NSFileManager defaultManager] removeItemAtPath:filepath error:&error];
    //        }
    //        NSError *error;
    //        NSString *filepath = [self.imageArray objectAtIndex:index];
    //        [[NSFileManager defaultManager] removeItemAtPath:filepath error:&error];
    //    } else if ([messagePhotoItemView.dataType isEqualToString:@"picture"]) {
    //        NSError *error;
    //        NSString *filepath = [self.imageArray objectAtIndex:index];
    //        [[NSFileManager defaultManager] removeItemAtPath:filepath error:&error];
    //    } else {
    //        //music
    //        NSFileManager *fm = [NSFileManager defaultManager];
    //        NSArray *fileList = [[fm contentsOfDirectoryAtPath:sandBox error:nil] pathsMatchingExtensions:[NSArray arrayWithObjects:@"wav",@"amr",nil]];
    //        for (int i=0 ; i<[fileList count]; i++) {
    //            NSError *error;
    //            NSString *filepath = [sandBox stringByAppendingPathComponent:[fileList objectAtIndex:i]];
    //            [[NSFileManager defaultManager] removeItemAtPath:filepath error:&error];
    //        }
    //        NSError *error;
    //        NSString *filepath = [self.imageArray objectAtIndex:index];
    //        [[NSFileManager defaultManager] removeItemAtPath:filepath error:&error];
    //    }
    //    [self.itemArray removeObjectAtIndex:index];
    //    [self.imageArray removeObjectAtIndex:index];
    //    [self updateScrollView:self.itemArray];
    
}

@end
